//
// C:\Program Files (x86)\FlashDevelop\Tools\flexsdk\frameworks\libs\player\10.0\playerglobal.swc\flash\display\Graphics
//
package flash.display
{
	import flash.display.Shader;
	import flash.geom.Matrix;
	import flash.display.BitmapData;
	import flash.display.IGraphicsStroke;
	import flash.display.IGraphicsPath;
	import flash.display.IGraphicsFill;
	import flash.display.IGraphicsData;
	import flash.display.Graphics;
	import flash.utils.Dictionary;
	import js.element.canvas.CanvasRenderingContext2D;

	/**
	 * The Graphics class contains a set of methods that you can use to create a vector shape. 
	 * Display objects that support drawing include Sprite and Shape objects.
	 * Each of these classes includes a <codeph class="+ topic/ph pr-d/codeph ">graphics</codeph> property that is a Graphics object. 
	 * The following are among those helper functions provided for ease of use: 
	 * <codeph class="+ topic/ph pr-d/codeph ">drawRect()</codeph>, <codeph class="+ topic/ph pr-d/codeph ">drawRoundRect()</codeph>, 
	 * <codeph class="+ topic/ph pr-d/codeph ">drawCircle()</codeph>, and <codeph class="+ topic/ph pr-d/codeph ">drawEllipse()</codeph>.
	 * 
	 *   <p class="- topic/p ">You cannot create a Graphics object directly from ActionScript code. 
	 * If you call <codeph class="+ topic/ph pr-d/codeph ">new Graphics()</codeph>, an exception is thrown.</p><p class="- topic/p ">The Graphics class is final; it cannot be subclassed.</p>
	 * 
	 *   EXAMPLE:
	 * 
	 *   The following example uses the GraphicsExample class to draw a circle,
	 * a rounded rectangle, and a square.  This task is accomplished by using the following steps:
	 * <ol class="- topic/ol "><li class="- topic/li ">Declare a <codeph class="+ topic/ph pr-d/codeph ">size</codeph> property for later use in determining the size of each shape.</li><li class="- topic/li ">Declare properties that set the background color to orange, the border color to
	 * dark gray, the border size to 0 pixels, the corner radius to 9 pixels, and set the space
	 * between the stage edge and the other objects to be 5 pixels.</li><li class="- topic/li ">Use the properties declared in the preceding steps along with the built in methods of the
	 * Graphics class to draw the circle, rounded rectangle, and square at coordinates x = 0, y = 0.</li><li class="- topic/li ">Redraw each of the shapes along the top of the stage, starting at x = 5, y = 5, with
	 * a 5-pixel spacing between shapes.</li></ol><codeblock xml:space="preserve" class="+ topic/pre pr-d/codeblock ">
	 * 
	 *   package {
	 * import flash.display.DisplayObject;
	 * import flash.display.Graphics;
	 * import flash.display.Shape;
	 * import flash.display.Sprite;
	 * 
	 *   public class GraphicsExample extends Sprite {
	 * private var size:uint         = 80;
	 * private var bgColor:uint      = 0xFFCC00;
	 * private var borderColor:uint  = 0x666666;
	 * private var borderSize:uint   = 0;
	 * private var cornerRadius:uint = 9;
	 * private var gutter:uint       = 5;
	 * 
	 *   public function GraphicsExample() {
	 * doDrawCircle();
	 * doDrawRoundRect();
	 * doDrawRect();
	 * refreshLayout();
	 * }
	 * 
	 *   private function refreshLayout():void {
	 * var ln:uint = numChildren;
	 * var child:DisplayObject;
	 * var lastChild:DisplayObject = getChildAt(0);
	 * lastChild.x = gutter;
	 * lastChild.y = gutter;
	 * for (var i:uint = 1; i &lt; ln; i++) {
	 * child = getChildAt(i);
	 * child.x = gutter + lastChild.x + lastChild.width;
	 * child.y = gutter;
	 * lastChild = child;
	 * }
	 * }
	 * 
	 *   private function doDrawCircle():void {
	 * var child:Shape = new Shape();
	 * var halfSize:uint = Math.round(size / 2);
	 * child.graphics.beginFill(bgColor);
	 * child.graphics.lineStyle(borderSize, borderColor);
	 * child.graphics.drawCircle(halfSize, halfSize, halfSize);
	 * child.graphics.endFill();
	 * addChild(child);
	 * }
	 * 
	 *   private function doDrawRoundRect():void {
	 * var child:Shape = new Shape();
	 * child.graphics.beginFill(bgColor);
	 * child.graphics.lineStyle(borderSize, borderColor);
	 * child.graphics.drawRoundRect(0, 0, size, size, cornerRadius);
	 * child.graphics.endFill();
	 * addChild(child);
	 * }
	 * 
	 *   private function doDrawRect():void {
	 * var child:Shape = new Shape();
	 * child.graphics.beginFill(bgColor);
	 * child.graphics.lineStyle(borderSize, borderColor);
	 * child.graphics.drawRect(0, 0, size, size);
	 * child.graphics.endFill();
	 * addChild(child);
	 * }
	 * }
	 * }
	 * </codeblock>
	 * @langversion	3.0
	 * @playerversion	Flash 9
	 * @playerversion	Lite 4
	 */
	public final class Graphics extends Object
	{
		private var _forms:Array=[];
		
		public function Graphics ()
		{
		}
		
		public function beginBitmapFill (bitmap:BitmapData, matrix:Matrix=null, repeat:Boolean=true, smooth:Boolean=false) : void;

		public function beginFill (color:uint, alpha:Number = 1) : void
		{
			_forms.push(["p","fillStyle",color]);
			_forms.push(["p","globalAlpha",alpha]);
		}

		public function beginGradientFill (type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix=null, spreadMethod:String="pad", interpolationMethod:String="rgb", focalPointRatio:Number=0) : void;

		public function beginShaderFill (shader:Shader, matrix:Matrix=null) : void;

		public function clear () : void
		{
			_forms = [];
		}

		public function copyFrom (sourceGraphics:Graphics) : void;

		public function curveTo (controlX:Number, controlY:Number, anchorX:Number, anchorY:Number) : void;
		

		public function drawCircle (x:Number, y:Number, radius:Number) : void
		{
			_forms.push(["f", "arc", [x, y, radius, 0, Math.PI * 2, true]]);
		}

		public function drawEllipse (x:Number, y:Number, width:Number, height:Number) : void
		{
			_forms.push(["f", "arc", [x, y, width*0.5, height*0.5, Math.PI * 2, true]]);
		}

		public function drawGraphicsData (graphicsData:Vector.<flash.display.IGraphicsData>) : void;

		public function drawPath (commands:Vector.<int>, data:Vector.<Number>, winding:String="evenOdd") : void;

		public function drawRect (x:Number, y:Number, width:Number, height:Number) : void
		{
			
			_forms.push(["m","fillRect",[x, y, width, height]]);
		}
		

		public function drawRoundRect (x:Number, y:Number, width:Number, height:Number, ellipseWidth:Number, ellipseHeight:Number = null) : void
		{
			moveTo(x + r, y);
			
			ctx.lineTo(x + width - ellipseWidth, y);
			ctx.quadraticCurveTo(x + width, y, x + width, y + ellipseHeight);
			ctx.lineTo(x + width, y + height - ellipseHeight);
			
		}
		
		private function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
			if (typeof stroke == "undefined" ) {
				stroke = true;
			}
			if (typeof radius === "undefined") {
				radius = 5;
			}
			ctx.beginPath();
			ctx.moveTo(x + radius, y);
			ctx.lineTo(x + width - radius, y);
			ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
			ctx.lineTo(x + width, y + height - radius);//#
			ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
			ctx.lineTo(x + radius, y + height);
			ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
			ctx.lineTo(x, y + radius);
			ctx.quadraticCurveTo(x, y, x + radius, y);
			ctx.closePath();
			if (stroke) {
			ctx.stroke();
			}
			if (fill) {
			ctx.fill();
			}        
		}

		public function drawRoundRectComplex (x:Number, y:Number, width:Number, height:Number, topLeftRadius:Number, topRightRadius:Number, bottomLeftRadius:Number, bottomRightRadius:Number) : void;

		public function drawTriangles (vertices:Vector.<Number>, indices:Vector.<int>=null, uvtData:Vector.<Number>=null, culling:String="none") : void;

		public function endFill () : void
		{
			_forms.push(["m", "fill", []]);
			
		}

		

		public function lineBitmapStyle (bitmap:BitmapData, matrix:Matrix=null, repeat:Boolean=true, smooth:Boolean=false) : void;

		public function lineGradientStyle (type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix=null, spreadMethod:String="pad", interpolationMethod:String="rgb", focalPointRatio:Number=0) : void;

		public function lineShaderStyle (shader:Shader, matrix:Matrix=null) : void;

		public function lineStyle (thickness:Number=null, color:uint=0, alpha:Number=1, pixelHinting:Boolean=false, scaleMode:String="normal", caps:String=null, joints:String=null, miterLimit:Number=3) : void;

		public function lineTo (x:Number, y:Number) : void
		{
			_forms.push(["m","lineTo",[x, y]]);
		}


		public function moveTo (x:Number, y:Number) : void
		{
			_forms.push(["m","beginPath",[]);
			_forms.push(["m","moveTo",[x, y]]);
		}
		
		public function render(context:CanvasRenderingContext2D):void 
		{
			var len:Number = _forms.length;
			for (var i:int = 0; i < len; i++)
			{
				v = _forms[i];
				if(v[0]="m")
					context[v[1]].apply(context, v[2]);
				else if(v[0]="p")
					context[v[1]] = v[2];
			}
		}
	}
}